<template>
    <el-upload
        class="avatar-uploader"
        :action="imgLoadPath"
        :show-file-list="false"
        :on-success="handleBeforeUpload1"
        :before-upload="beforeUpload"
    >
        <el-button type="primary" size="medium" >{{uploadTitle}}</el-button>
    </el-upload>
</template>

<script>
import api from '@/api/index';
export default {
    name: 'IDReady',
    props: ['imgUrl','title','collback','contractid'],
    data() { 
        return {
            imgModelUrl: '',
            imgLoadPath: api.API_PATH + api.UPLOAD_FILE,
            uploadLogin: null,
            uploadTitle:'上传'
        };
    },
    created() {
        if (this.title) {
            this.uploadTitle = this.title;
        }
    },
    methods: {
        //身份证正面上传成功
        handleBeforeUpload1(response) {
            this.uploadLogin.close();
            if (response.code == 1) {
                if(typeof this.collback == 'function') this.collback(response.data,this.contractid)
            } else {
                this.$message.error(response.msg);
            }
        },
        beforeUpload: function (file) {
            var FileExt = file.name.replace(/.+\./, '');
            if (['jpg', 'jpeg', 'png','pdf'].indexOf(FileExt.toLowerCase()) === -1) {
                this.$message({
                    type: 'warning',
                    message: '请上传jpg,jpeg,png,pdf格式文件！'
                });
                return false;
            }
            this.uploadLogin = this.$loading({ text: '加载中...' });
        }
    }
};
</script>

<style scoped>
.zhenjian-id-box {
    width: 150px;
    height: 150px;
    font-size: 14px;
    color: #888;
    text-align: center;
    line-height: 150px;
    border-radius: 4px;
}
</style>
